<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	var proDefName;
	$(function() {
		$('#cc').combobox({
			url : '${pageContext.request.contextPath}/template/addUIData',
			valueField : 'id',
			textField : 'name',
			required : true,
			onSelect : function(param) {
				$("#proDefkey").val(param.name);
				$("#pdid").val(param.id);
			}
		});
		$('#templateAddForm').form({//
			url : '${pageContext.request.contextPath}/template/add?',
			onSubmit : function() {
				progressLoad();
				$("#fieldCount").val(i_add_type);
				var isValid = $(this).form('validate');
				if (!isValid) {
					progressClose();
				}
				return isValid;
			},
			success : function(result) {
				progressClose();
				result = $.parseJSON(result);
				if (result.success) {
					parent.$.modalDialog.handler.dialog('close');
					parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
				} else {
					parent.$.messager.alert('错误', result.msg,'error');
				}
			}
		});
	});
	var i_add_type = 0;
	var i_add_content = 0;
	function add() {
		var fieldType = "fieldType"+ i_add_type++ ;
		var fieldContent = "fieldContent"+ i_add_content++ ;
		var row = "<tr class='maybeDelete'><td><a class='deleteLink' href='#'>删除</a></td><td>"//
				+ "<input id='"+fieldType+"' type='text' name='"+fieldType+"' class='easyui-validatebox' data-options='required:true'/></td>"//
				+ "<td>"//
				+ "<input id='"+fieldContent+"' type='text' name='"+fieldContent+"' class='easyui-validatebox' data-options='required:true'/></td></tr>";
		$("#tbody").append(row);
		$("#" + fieldType).val($("#fieldTypeFake").val());
		$("#" + fieldContent).val($("#fieldContentFake").val());
		$(".deleteLink").click(deleteField);
	}
	function deleteField(){
		$(this).parents(".maybeDelete").last().remove();
	}
	$('#comboBoxCC').combobox({  
	    url:'${pageContext.request.contextPath}/admin/getFields',  
	    valueField:'id', 
	    value:'...', 
	    textField:'name', 
	    required:true,  
	    onSelect:function(rec){
			$('#fieldContentFake').val(rec.name);
		}
	}); 
</script>
<style type="text/css">
</style>
<div style="margin: 5px">
	<form id="templateAddForm" method="post">
		<input id="proDefkey" type="hidden" name="processDefinitionKey" value="">
		<input id="pdid" type="hidden" name="pdid" value="">
		<input id="fieldCount" type="hidden" name="fieldCount" value="">
		<table cellspacing="0" cellpadding="3" border="1" style="width: 100%">
			<tbody>
				<tr bgcolor="#398EB7">
					<td colspan="2">模板基本信息</td>
				</tr>
				<tr>
					<td>模板名称</td>
					<td><input name="name" id="vv" class="easyui-validatebox" data-options="required:true" /></td>
				</tr>
				<tr>
					<td>所用流程</td>
					<td><input id="cc" name="roomName"></td>
				</tr>
			</tbody>
		</table>
		<br> 流程字段： <select id="fieldTypeFake" class="" name="dept" style="width:200px;">
			<option value="validateBox">validateBox</option>
			<option value="comboBox">comboBox</option>
			<option value="textarea">textarea</option>
			<option value="datetimeBox">datetimeBox</option>
			<option value="dateTimeBox">dateBox</option>
			<option value="checkBox">checkBox</option>
			<option value="comboGrid">comboGrid</option>
		</select> 
		<input id="fieldContentFake" name="fieldContentFake" type="hidden" /> 
		字段内容: <input id="comboBoxCC" name="xx" /> 
		<a id="btn" href="javascript:add()" class="easyui-linkbutton">添加</a>
		<table cellspacing="0" cellpadding="3" border="1" style="width: 100%">
			<tbody id="tbody">
				<tr bgcolor="#398EB7">
					<td><font color="#ffffff"></font></td>
					<td><font color="#ffffff">字段类型</font></td>
					<td><font color="#ffffff">字段内容</font></td>
				</tr>
			</tbody>
		</table>
	</form>
</div>